<?php
namespace app\admin\controller;
use app\admin\logic\welcome\WelcomeLogic;
use app\api\controller\v1\pay;
use think\Db;
use think\Request;

class Index extends Base
{
	public function _initialize()
	{
		// 调用父类前置方法
		parent::_initialize();
		
		// 登录校验
		$this->IsLogin();
	}

	public function index()
	{
		return $this->fetch();
	}

    public function welcome(){

    }

	public function show()
	{
        $ids = [1,8];
        $id_s = Db::name('proxy')->where('proxy_id','in',$ids)->column('shi');
        $orders = Db::name('order')->where('status',6)->where('shi','in',$id_s)->column('id');
        $list = Db::name('balance')->where('order_id','in',$orders)->select();


        $m = date('Y-m',strtotime(date('Y-m',time()).'-1 00:00:00') -1 );
        $mm = date('Y-m-d',strtotime(date('Y-m',time()).'-1 00:00:00') -1 );

        $all_data = WelcomeLogic::get_money_data();
        $this->assign('money',$all_data);

        $prople = WelcomeLogic::get_people();
        $this->assign('people',$prople);

        $city_list = WelcomeLogic::city_list();
        $this->assign('city',$city_list);

		return $this->fetch();
	}

    public function techn_ph(Request $request){
        $param = $request->param();

        $type = !empty($param['techn_type'])? $param['techn_type']:'';
        $zhou = !empty($param['techn_zhou'])? $param['techn_zhou']:'';

        $techn_list = WelcomeLogic::techn_list($type,$zhou);
        echo json_encode(['code'=>0,'msg'=>'成功','data'=>$techn_list]);

    }
    public function center_math(Request $request){
        $time = $request->param();
        if (!empty($time['month_name'])){
            $min_time = strtotime(date('Y-',time()).$time['month_name'].'-01 00:00:00');
            $man_time = strtotime(date('Y-',time()).($time['month_name']+1).'-01 00:00:00');
            $month = $time['month_name'];
        }else{
            $tm = date('m',time());
            $min_time = strtotime(date('Y-',time()).$tm.'-01 00:00:00');
            $man_time = strtotime(date('Y-',time()).($tm+1).'-01 00:00:00');
            $month = $tm;
        }

        if (!empty($time['day_name'])){
            $td = $time['day_name'];
            $min_day = strtotime(date('Y-',time()).$month.'-'.$time['day_name'].' 00:00:00');
            $man_day = strtotime(date('Y-',time()).$month.'-'.($time['day_name']+1).' 00:00:00');
        }else{
            $td = date('d',time());
            $min_day = strtotime(date('Y-',time()).$month.'-'.($td-1).' 00:00:00');
            $man_day = strtotime(date('Y-',time()).$month.'-'.($td).' 00:00:00');
        }

        $info[0] = WelcomeLogic::get_money_data();
        $info[0]['timestatus'] = '总计';

        $info[1] = WelcomeLogic::get_money_data($min_time,$man_time);
        $info[1]['timestatus'] = empty($time['month_name'])?$tm.'月明细':$time['month_name'].'月明细';

        $min_today = strtotime(date('Y-m-d',time()));
        $max_today = $min_today+86399;
//        $min_yesterday = $min_today - 86400;
//        $max_yesterday = $min_yesterday + 86399;
        $info[2] = WelcomeLogic::get_money_data($min_day,$man_day);
        if (!empty($time['day_name'])){
            $info[2]['timestatus'] = $td.'日明细';

        }else{
            $info[2]['timestatus'] = '昨日明细';

        }

        $info[3] = WelcomeLogic::get_money_data($min_today,$max_today);
        $info[3]['timestatus'] = '今日明细';


        echo json_encode(['code'=>0,'msg'=>'成功','data'=>$info]);
    }


    public function proxy(Request $request){
        $proxy_id = $request->param();
        $proxy_id = $proxy_id['proxy_id'];
        $time = $request->param();
        if (!empty($time['month_name'])){
            $min_time = strtotime(date('Y-',time()).$time['month_name'].'-01 00:00:00');
            $man_time = strtotime(date('Y-',time()).($time['month_name']+1).'-01 00:00:00');
            $month = $time['month_name'];
        }else{
            $tm = date('m',time());
            $min_time = strtotime(date('Y-',time()).$tm.'-01 00:00:00');
            $man_time = strtotime(date('Y-',time()).($tm+1).'-01 00:00:00');
            $month = $tm;
        }

        if (!empty($time['day_name'])){
            $td = $time['day_name'];
            $min_day = strtotime(date('Y-',time()).$month.'-'.$time['day_name'].' 00:00:00');
            $man_day = strtotime(date('Y-',time()).$month.'-'.($time['day_name']+1).' 00:00:00');
        }else{
            $td = date('d',time());
            $min_day = strtotime(date('Y-',time()).$month.'-'.($td-1).' 00:00:00');
            $man_day = strtotime(date('Y-',time()).$month.'-'.$td.' 00:00:00');
        }

        $info[0] = WelcomeLogic::get_proxy_money_data(null,null,$proxy_id);
        $info[0]['timestatus'] = '总计';

        $info[1] = WelcomeLogic::get_proxy_money_data($min_time,$man_time,$proxy_id);
        $info[1]['timestatus'] = empty($time['month_name'])?$tm.'月明细':$time['month_name'].'月明细';

        $min_today = strtotime(date('Y-m-d',time()));
        $max_today = $min_today+86399;
        $min_yesterday = $min_today - 86400;
        $max_yesterday = $min_yesterday + 86399;
        $info[2] = WelcomeLogic::get_proxy_money_data($min_day,$man_day,$proxy_id);
        if (!empty($time['day_name'])){
            $info[2]['timestatus'] = $td.'日明细';

        }else{
            $info[2]['timestatus'] = '昨日明细';

        }

        $info[3] = WelcomeLogic::get_proxy_money_data($min_today,$max_today,$proxy_id);
        $info[3]['timestatus'] = '今日明细';


        echo json_encode(['code'=>0,'msg'=>'成功','data'=>$info]);
    }


    public function getdata(){

        $data = WelcomeLogic::get_data();

        return $data;
    }
}